import { Engine } from './engine'

/**
 * 默认子弹对象
 *
 * @class bullet
 */
class bullet {
    constructor(r) {
        /**
         * 子弹类型
         * @memberof bullet
         */
        this.type = "bullet";
        /**
         * 子弹半径
         * @memberof bullet
         */
        this.r = r;
        /**
         * 子弹X轴坐标
         * @memberof bullet
         */
        this.x = 0;
        /**
         * 子弹Y轴坐标
         * @memberof bullet
         */
        this.y = 0;
        /**
         * 子弹颜色
         * @memberof bullet
         */
        this.color = "#ffffff";
        /**
         * 子弹运动方向值
         * @memberof bullet
         */
        this.direction = 5;
        /**
         * 子弹伤害值
         * @memberof bullet
         */
        this.hit = 1;
        /**
         * 渲染引擎对象
         * @memberof bullet
         */
        this.DrawEvent = Engine;
    }

    /**
     * 计算子弹位置
     *
     * @memberof bullet
     */
    timer() {
        this.y += this.direction;
    }
    /**
     * 在画布上渲染子弹
     *
     * @param {canvas} c canvas绘图对象
     * @return {Blob} 是否渲染 
     * @memberof bullet
     */
    draw(c) {
        if (this.y - this.r > this.DrawEvent.realHeight || this.x - this.r > this.DrawEvent.realWidth) {
            return false;
        } else {
            c.translate(this.x, this.y);
            this.timer();
            c.beginPath();
            c.arc(0, 0, this.r, 0, Math.PI * 2);
            c.globalAlpha = 1;
            c.strokeStyle = this.color;
            c.lineWidth = 0.5;
            c.stroke();
            c.restore();
            return true;
        }
    }
}

export { bullet }